package wodegua.d29_多线程;

import java.util.concurrent.*;

/**
 * 掌握线程池的创建
 */
public class d7_ThreadPoolExecutorRunnable {
    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(3,5,2, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3)
                , Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        //执行 Runnable 任务
        Runnable r = new MyRunnablePool();
        pool.execute(r);
        pool.execute(r);
        pool.execute(r);
        pool.execute(r);
        pool.execute(r);
        pool.execute(r);

        //-创建临时线程
        pool.execute(r);
        pool.execute(r);
        //拒绝策略
//        pool.execute(r);

        pool.shutdown();
//        pool.shutdownNow();
    }
}

class MyRunnablePool implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "执行~~~");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
